package com.ce.source.analysis.gc;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：前世小和尚（xiaopingzhang8@creditease.cn）
 * @Description ：gc收集器
 * @ClassName ：GcCollector
 * @Company ：普信恒业科技发展（北京）有限公司
 * @date ：2018/3/19 15:27
 * <pre>
 *     <ul>
 *         使用serial收集器
 *         <li>-Xms30M -Xmx30M -Xmn10M -XX:+PrintTenuringDistribution -XX:+UseSerialGC -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:SurvivorRatio=8</li>
 *         <li>
 * [GC[DefNew
 * Desired survivor size 524288 bytes, new threshold 1 (max 15)
 * - age   1:    1042176 bytes,    1042176 total
 * : 5561K->1017K(9216K), 0.0062277 secs] 5561K->4089K(29696K), 0.0062893 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
 * [GC[DefNew
 * Desired survivor size 524288 bytes, new threshold 1 (max 15)
 * - age   1:    1048568 bytes,    1048568 total
 * : 9209K->1023K(9216K), 0.0089556 secs] 12281K->10677K(29696K), 0.0090059 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
 * [Full GC[Tenured: 9653K->10565K(20480K), 0.0410418 secs] 11337K->10565K(29696K), [Perm : 7344K->7344K(21248K)], 0.0411384 secs] [Times: user=0.03 sys=0.00, real=0.04 secs]
 * [GC[DefNew
 * Desired survivor size 524288 bytes, new threshold 15 (max 15)
 * - age   1:      55800 bytes,      55800 total
 * : 6840K->54K(9216K), 0.0051118 secs] 17406K->16764K(29696K), 0.0051608 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
 * [GC[DefNew: 6414K->6414K(9216K), 0.0000364 secs][Tenured: 16709K->1230K(20480K), 0.0198160 secs] 23124K->1230K(29696K), [Perm : 7393K->7393K(21248K)], 0.0199247 secs] [Times: user=0.01 sys=0.00, real=0.02 secs]
 * Heap
 * def new generation   total 9216K, used 6361K [0x00000000f9000000, 0x00000000f9a00000, 0x00000000f9a00000)
 * eden space 8192K,  77% used [0x00000000f9000000, 0x00000000f96364b8, 0x00000000f9800000)
 * from space 1024K,   0% used [0x00000000f9900000, 0x00000000f9900000, 0x00000000f9a00000)
 * to   space 1024K,   0% used [0x00000000f9800000, 0x00000000f9800000, 0x00000000f9900000)
 * tenured generation   total 20480K, used 1230K [0x00000000f9a00000, 0x00000000fae00000, 0x00000000fae00000)
 * the space 20480K,   6% used [0x00000000f9a00000, 0x00000000f9b33960, 0x00000000f9b33a00, 0x00000000fae00000)
 * compacting perm gen  total 21248K, used 7406K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
 * the space 21248K,  34% used [0x00000000fae00000, 0x00000000fb53bb60, 0x00000000fb53bc00, 0x00000000fc2c0000)
 * No shared spaces configured.
 *         </li>
 *     </ul>
 *     <ul>
 *         使用Parallel收集器
 *         <li>-Xms30M -Xmx30M -Xmn10M -XX:+PrintTenuringDistribution -XX:+UseParallelGC -XX:+PrintGCDetails -XX:SurvivorRatio=8</li>
 *         <li>
 * [GC
 * Desired survivor size 1048576 bytes, new threshold 7 (max 15)
 * [PSYoungGen: 8155K->728K(9216K)] 8155K->6872K(29696K), 0.0083715 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
 * [GC
 * Desired survivor size 1048576 bytes, new threshold 7 (max 15)
 * [PSYoungGen: 7216K->720K(9216K)] 13360K->13008K(29696K), 0.0075350 secs] [Times: user=0.05 sys=0.01, real=0.01 secs]
 * [GC
 * Desired survivor size 1048576 bytes, new threshold 7 (max 15)
 * [PSYoungGen: 6927K->728K(9216K)] 19215K->19160K(29696K), 0.0079740 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
 * [Full GC [PSYoungGen: 728K->0K(9216K)] [ParOldGen: 18432K->19070K(20480K)] 19160K->19070K(29696K) [PSPermGen: 3232K->3231K(21504K)], 0.0338301 secs] [Times: user=0.06 sys=0.00, real=0.03 secs]
 * [Full GC [PSYoungGen: 6186K->0K(9216K)] [ParOldGen: 19070K->3710K(20480K)] 25256K->3710K(29696K) [PSPermGen: 3231K->3231K(21504K)], 0.0084433 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
 * Heap
 * PSYoungGen      total 9216K, used 3154K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
 * eden space 8192K, 38% used [0x00000000ff600000,0x00000000ff914820,0x00000000ffe00000)
 * from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
 * to   space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 * ParOldGen       total 20480K, used 3710K [0x00000000fe200000, 0x00000000ff600000, 0x00000000ff600000)
 * object space 20480K, 18% used [0x00000000fe200000,0x00000000fe59fa48,0x00000000ff600000)
 * PSPermGen       total 21504K, used 3238K [0x00000000f9000000, 0x00000000fa500000, 0x00000000fe200000)
 * object space 21504K, 15% used [0x00000000f9000000,0x00000000f9329880,0x00000000fa500000)
 *         </li>
 *     </ul>
 *     <ul>
 *         使用UseParNewGC+CMS收集器
 *         <li>-Xms30M -Xmx30M -Xmn10M -XX:+PrintTenuringDistribution -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection
 *         -XX:CMSFullGCsBeforeCompaction=0 -XX:+PrintGCDetails
 *         -XX:SurvivorRatio=8</li>
 *         <li>
 * [GC[ParNew
 * Desired survivor size 524288 bytes, new threshold 1 (max 15)
 * - age   1:     694400 bytes,     694400 total
 * : 8154K->702K(9216K), 0.0051337 secs] 8154K->6848K(29696K), 0.0052074 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
 * [GC[ParNew
 * Desired survivor size 524288 bytes, new threshold 15 (max 15)
 * - age   1:        256 bytes,        256 total
 * : 7190K->251K(9216K), 0.0053689 secs] 13336K->13188K(29696K), 0.0054234 secs] [Times: user=0.05 sys=0.00, real=0.01 secs]
 * [GC [1 CMS-initial-mark: 12936K(20480K)] 16260K(29696K), 0.0001614 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
 * [CMS-concurrent-mark: 0.005/0.005 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
 * [CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
 * [GC[ParNew
 * Desired survivor size 524288 bytes, new threshold 15 (max 15)
 * - age   2:        256 bytes,        256 total
 * : 6459K->94K(9216K), 0.0073325 secs] 19396K->19175K(29696K), 0.0074384 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
 * [CMS-concurrent-abortable-preclean: 0.003/2.005 secs] [Times: user=0.00 sys=0.00, real=2.01 secs]
 * [GC[YG occupancy: 3166 K (9216 K)][Rescan (parallel) , 0.0010572 secs][weak refs processing, 0.0000191 secs][scrub string table, 0.0002575 secs] [1 CMS-remark: 19080K(20480K)] 22247K(29696K), 0.0014668 secs] [Times: user=0.06 sys=0.00, real=0.00 secs]
 * [CMS-concurrent-sweep: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
 * [CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
 * [GC [1 CMS-initial-mark: 19080K(20480K)] 25416K(29696K), 0.0003116 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
 * [GC[ParNew: 6335K->6335K(9216K), 0.0000686 secs][CMS[CMS-concurrent-mark: 0.006/0.006 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
 * (concurrent mode failure): 19080K->3710K(20480K), 0.0219877 secs] 25416K->3710K(29696K), [CMS Perm : 3233K->3232K(21248K)], 0.0221897 secs] [Times: user=0.02 sys=0.00, real=0.02 secs]
 * Heap
 * par new generation   total 9216K, used 3154K [0x00000000f9000000, 0x00000000f9a00000, 0x00000000f9a00000)
 * eden space 8192K,  38% used [0x00000000f9000000, 0x00000000f9314820, 0x00000000f9800000)
 * from space 1024K,   0% used [0x00000000f9900000, 0x00000000f9900000, 0x00000000f9a00000)
 * to   space 1024K,   0% used [0x00000000f9800000, 0x00000000f9800000, 0x00000000f9900000)
 * concurrent mark-sweep generation total 20480K, used 3710K [0x00000000f9a00000, 0x00000000fae00000, 0x00000000fae00000)
 * concurrent-mark-sweep perm gen total 21248K, used 3239K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
 *         </li>
 *     </ul>
 *     <ul>
 *        Parallel Scavenge收集器
 *        <li>-Xms30M -Xmx30M -Xmn10M -XX:+PrintTenuringDistribution -XX:+UseParallelGC -XX:+UseParallelOldGC  -XX:+PrintGCDetails -XX:SurvivorRatio=8</li>
 *     </ul>
 * </pre>
 */
public class GcCollector {
    public static void main(String[] args) throws Exception {
        List<Object> caches = new ArrayList<Object>();
        for (int i = 0; i < 7; i++) {
            caches.add(new byte[1024 * 1024 * 3]);
            Thread.sleep(1000);
        }
        caches.clear();
        for (int i = 0; i < 2; i++) {
            caches.add(new byte[1024 * 1024 * 3]);
            Thread.sleep(1000);
        }
    }
}
